
package DataObjects;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import java.util.Vector;

import javax.swing.JOptionPane;

import Messages.MessageAddWorkingHours;
import Messages.MessageAddWorkingHoursReply;
import Messages.MessageSavingReply;

public class CheckHoursInDate implements Serializable {
	
	 
	private static final long serialVersionUID = 1L;
	 
//	private MainMenu mainMenu;
	private Vector<String> dayHrs;	
	private Vector <String> hours;	
	private Date dateOut;
	private Date dateIn;
	private Date clockOut;
	private Date clockIn;
	private int flag;
	private long totalDayTime;
	private String hoursOfMonth;
	private String minutesOfMonth;
	private String secondsOfMonth;
	 
	
	public CheckHoursInDate(Vector<String> vec)
	{
		
	      
	      DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); //("yyyy-MM-dd HH:mm:ss");
		 String inputString = (String) vec.get(0);  		 
		 try {
			this.dateIn=sdf.parse(inputString);

		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 
		 DateFormat sdf2 = new SimpleDateFormat("HH:mm:ss");
		 inputString = (String) vec.get(1);
		 try {
			this.clockIn=sdf2.parse(inputString);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		 inputString = (String) vec.get(2);  
		 try {
			this.dateOut= sdf.parse(inputString);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		 inputString = (String) vec.get(3);
		 try {
			this.clockOut=sdf2.parse(inputString);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 
	}

	
	public Vector <String> getwrkHRS() {
		return hours;
	}

	
	public void setwrkHRS(Vector <String> vecwrkHRS) {
		this.hours = vecwrkHRS;
	}

	public boolean CalculateDayHours() throws ParseException
	{
		
		DateFormat sdf = new SimpleDateFormat("HH:mm:ss");
	 
	    long res1 = dateOut.getTime();
	    long res2 = dateIn.getTime();
		long clckIn = clockIn.getTime();
		long clckOut = clockOut.getTime(); 
		
		        if(res2==(res1-86400000)&&clckIn>clckOut)
		        {   
		        	String inputStringTwelwe = (String)"00:00:00";
		        	 
			        Date dateTwelwe = sdf.parse(inputStringTwelwe);
			        
			        long res3 = dateTwelwe.getTime();                                                //problema   [solved]
				    
			        String inputStringTwelwe2 = (String)"23:59:59";
		        	 
			        Date dateTwelwe2 = sdf.parse(inputStringTwelwe2);
			       
			        long res4 = dateTwelwe2.getTime();                                                //problema   [solved]
				     
			        long resultTwelwe1= (int)Math.abs(res4 - clckIn);             ///60000 ;
			        
			        long resultTwelwe2= (int)Math.abs(clckOut - res3);            ///60000 ;
			        
			        long result= (int) (resultTwelwe1 + resultTwelwe2)  ;    // v minutah 
			        
			          totalDayTime=result; 
				      long diffHours = totalDayTime / (60 * 60 * 1000);   
				        
				        if(diffHours<=12)
				        {
				        	 setHoursOfDay(String.valueOf(diffHours));       
						      
				        	return false;
				        	
				        }
		        }
		        
		        else if((res2==res1&&clckIn<clckOut))
		        {	
		        	totalDayTime = (int)Math.abs(clckOut - clckIn);      ///60000 ;    // v minutah 
		        	
		        	long diffHours = totalDayTime / (60 * 60 * 1000);   
			        
			        if(diffHours<=12)
			        {
			        	 setHoursOfDay(String.valueOf(diffHours));    
			        	 
			        	return false;
			        	
			        }      	 
		        }
		        
		    
		   
				return true;  
		       	 
		        
		   }
		       	 
		   	 
	public String getHoursOfMonth() {
		return hoursOfMonth;
	}


	public void setHoursOfDay(String hoursOfMonth) {
		this.hoursOfMonth = hoursOfMonth;
	}

	 
	
	
	public String getMinutesOfMonth() {
		return minutesOfMonth;
	}


	public void setMinutesOfMonth(String minutesOfMonth) {
		this.minutesOfMonth = minutesOfMonth;
	}


	public String getSecondsOfMonth() {
		return secondsOfMonth;
	}


	public void setSecondsOfMonth(String secondsOfMonth) {
		this.secondsOfMonth = secondsOfMonth;
	}
	
	
}
